package com.ybfenpan.controller.member.wealth;


import com.ybfenpan.controller.core.BaseController;
import com.ybfenpan.model.Member;
import com.ybfenpan.model.WageCurrent;
import com.ybfenpan.service.WageCurrentService;
import com.ybfenpan.service.WageHistoryService;
import com.ybfenpan.taglib.pagetag.Pagination;
import com.ybfenpan.utils.ContextUtil;
import com.ybfenpan.utils.MapUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;


/**
 * Created by Administrator on 2016/3/25.
 */
@Controller

public class WageListController extends BaseController {
    @Resource
    private WageHistoryService wageHistoryService;
    @Resource
    private WageCurrentService wageCurrentService;


    @RequestMapping("member/wealth/wageList.shtml")
    public String list(HttpServletRequest request) throws Exception {
        HashMap formMap = getParameterMap(request);
        String startDate = MapUtil.getString(formMap, "startDate");
        String endDate = MapUtil.getString(formMap, "endDate");

        if (startDate != null && !startDate.equals("") && endDate != null && !endDate.equals("")) {
            //+1天

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//小写的mm表示的是分钟

            Date newEndDate = sdf.parse(endDate);

            long temp = newEndDate.getTime() + 24 * 60 * 60 * 1000;
            newEndDate = new Date(temp);

            String newEndDateString = sdf.format(newEndDate);
            formMap.put("where", " a.commitDate>= '" + startDate + "' and a.commitDate<= '" + newEndDateString + "'");    //  时间查询
        }
        Member member = ContextUtil.getMember();
        formMap.put("where", "a.memberId = " + member.getId());
        formMap.put("pagination.orderBy", " a.id desc");  //排列
        Pagination page = wageHistoryService.queryForPageList("wageHistoryForPage", formMap);
        request.setAttribute(Pagination.pageBeanName, page);


        Integer wageCurrentId = member.getWageCurrentId();
        WageCurrent wage = wageCurrentService.getByKey(wageCurrentId);

        request.setAttribute("wage", wage);

        return "member/wealth/wageList";
    }


}
